from sqlalchemy import Column, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ...core.models.enums import SubscriptionType
from .base import TimedBaseModel


class ActivationCode(TimedBaseModel):
    __tablename__ = "activation_code"

    id: Mapped[int] = mapped_column(primary_key=True)
    title = Column(String(255), nullable=False)
    limit: Mapped[int] = mapped_column(server_default="0")
    reusable: Mapped[bool] = mapped_column(server_default="0")
    uses_number: Mapped[int] = mapped_column(server_default="0")
    subscription_type: Mapped[SubscriptionType]
    subscriptions = relationship("Subscription", back_populates="activation_code")

    def __str__(self):
        return self.title

    def __repr__(self):
        return f"<Код активации №{self.id} {self.title}>"
